/*	This file is part of LSAC.

	LSAC is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	LSAC is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with LSAC.  If not, see <http://www.gnu.org/licenses/>.

	Copyright (c) 2010 LEPESME "Jiboo" Jean-Baptiste
*/

#pragma once

#include "cExpression.h"
#include "lsac.h"

#include <typeinfo>
#include <cxxabi.h>
#include <malloc.h>

template<typename T>
class cExpPOD : public cExpression
{
public:
	T dValue;
	cExpPOD(cLocation pLocation, T pValue)
		: cExpression(pLocation)
	{
		this->dValue = pValue;
	}
	virtual ~cExpPOD() {}
	void print(int pLevel)
	{
		int lStatus;
		char *lDemangled = abi::__cxa_demangle(typeid(this->dValue).name(), 0, 0, &lStatus);
		PRINT_LOG("cExpPOD<" << lDemangled << "> " << (void*)this << " " << this->dValue); //FIXME: How to show T?
		free(lDemangled);
	}
	void validate(cSemContext *pContext)
	{
		// Nothing special?
	}
	eType getType(cSemContext *pContext)
	{
		if(typeid(this->dValue) == typeid(int))
		{
			return TYPE_INT;
		}
		else if(typeid(this->dValue) == typeid(bool))
		{
			return TYPE_BOOL;
		}
		return TYPE_VOID; // devrait jamais �tre retourn�
	}
	void validate() {}
	void genCode(ostream &pStream)
	{
		pStream << this->dValue;
	}
};
